package com.dayaokeji.rhythmschoolstudent.client.home.meeting.adapter;

import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.databases.dao.UserInfoDao;
import com.dayaokeji.rhythmschoolstudent.utils.RemoteHostUtil;
import com.dayaokeji.server_api.domain.Meeting;
import com.dayaokeji.server_api.domain.UserInfo;

/**
 * Created by Gorden on 2017/9/27.
 * 会议list adapter
 */

public class MeetingListAdapter extends BaseQuickAdapter<Meeting,BaseViewHolder> {

    public MeetingListAdapter() {
        super(R.layout.item_meeting_list, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, Meeting item) {
        helper.setText(R.id.tv_title,item.getName());
        helper.setText(R.id.tv_address,mContext.getString(R.string.address,item.getRoomName()));
        TextView tvHost = (TextView) helper.getView(R.id.tv_host);
        if (tvHost != null) {
            if (item.getFacilitatorInfoList().size() > 0 && item.getFacilitatorInfoList().get(0) != null) {
                tvHost.setText(mContext.getString(R.string.host,item.getFacilitatorInfoList().get(0).getUserName()));
            }else{
                tvHost.setVisibility(View.GONE);
            }
        }
        helper.setText(R.id.tv_date,item.getActStartTime());

        try{
            if (item.getFacilitatorInfoList() != null && item.getFacilitatorInfoList().size()>0) {
                for (Meeting.FacilitatorInfo facilitatorInfo : item.getFacilitatorInfoList()) {
                    final UserInfo userInfo = new UserInfo();
                    userInfo.setWorkNo(facilitatorInfo.getWorkNo());
                    userInfo.setName(facilitatorInfo.getUserName());
                    if (RemoteHostUtil.getCurrentRemoteHost() != null) {
                        userInfo.setUniversityId(RemoteHostUtil.getCurrentRemoteHost().getId() != null ? RemoteHostUtil.getCurrentRemoteHost().getId().longValue() : 0L);
                        UserInfoDao.saveUserInfo(userInfo);
                    }
                }
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
